home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / std / c++ / 965 < prev    next >
Encoding:
Internet Message Format  |  1996-08-06  |  2.4 KB

  1. From: "john (j.d.) hickin" <hickin@bnr.ca>
  2. Message-ID: <4jucle$i41@bmtlh10.bnr.ca>
  3. X-Original-Date: Wed, 3 Apr 1996 17:31:26 +0000
  4. Path: in1.uu.net!bounce-back
  5. Date: 05 Apr 96 02:13:52 GMT
  6. Approved: fjh@cs.mu.oz.au
  7. References: <009A04DA6A831C40.49800EAC@ittpub.nl>
  8. Subject: Re: sample auto_ptr template
  9. Newsgroups: comp.std.c++
  10. Organization: Bell Northern Research
  11. X-Mailer: Mozilla 1.1 (X11; I; HP-UX A.09.05 9000/715)
  12. X-Auth: PGPMoose V1.1 PGP comp.std.c++
  13.     iQBFAgUBMWSCHuEDnX0m9pzZAQHrcQF/YsQNbvrZH6RGfcX5M6fXK0WhFkXqWHQl
  14.     Dbz1gTCrY6N5xvk2+L1J+bjGqEEYI1DB
  15.     =MKTT
  16.  
  17. |> This is a terrible state of affairs, especially when we realize
  18. |> auto_ptr is the *only* smart pointer we have in the standard library.
  19. |> In my opinion, it should be renamed to zombie_ptr if it is to keep its
  20. |> new semantics.
  21.  
  22. It all depends what you want to use an auto_ptr for.  I have used classes
  23. like this way before templates or exception handling were added to C++.
  24. The main use was as insurance that certain resources were released on exit
  25. from a block in the face of multiple exit paths from the block.
  26.  
  27. The January DWP continues to say that auto_ptr provides strict ownership
  28. semantics [20.4.5  Template class auto_ptr]:
  29.  
  30. 2 The auto_ptr provides a semantics of strict ownership.  An object  may
  31.   be  safely  pointed  to  by  only one auto_ptr, so copying an auto_ptr
  32.   copies the pointer and transfers ownership to the destination.
  33.  
  34. The implementation you have quoted does not contradict the above statement.
  35. The January version of auto_ptr had the owner's stored pointer set to 0 so
  36. that dereferencing under such conditions was not allowed:
  37.  
  38. X& operator*() const;
  39.  
  40.   Requires:
  41.     get() != 0
  42.   Returns:
  43.     *get()
  44.  
  45. A simple amendment to the DWP, perhaps already in the works, is all we require:
  46.  
  47.  
  48. X& operator*() const;
  49.  
  50.   Requires:
  51.     owner == true
  52.   Returns:
  53.     *get()
  54.  
  55. With change, dereferencing will, as before, be undefined when ownership is 
  56. not held.
  57.  
  58.  
  59. -- 
  60. John Hickin      Nortel Technology, Montreal, Quebec
  61. (514) 765-7924   hickin@nortel.ca
  62. ---
  63. [ comp.std.c++ is moderated.  To submit articles: try just posting with      ]
  64. [ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu         ]
  65. [ FAQ:      http://reality.sgi.com/employees/austern_mti/std-c++/faq.html    ]
  66. [ Policy:   http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
  67. [ Comments? mailto:std-c++-request@ncar.ucar.edu                             ]
  68.